package com.mcx.modules.proto;

import com.mcx.modules.common.IProto;
import com.mcx.modules.common.MMO_DataStream;

import java.io.*;
import java.util.*;

/**
 * 客户端发送创建角色消息
 */
public class RoleOperation_CreatePlayerProto implements IProto
{
    private static MMO_DataStream dataStream = new MMO_DataStream();

    @Override
    public short getProtoCode() { return 10003; }

    public byte Sex; //性别
    public String RoleNickName; //角色名称

    public byte[] ToArray() {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try (DataOutputStream outputStream = new DataOutputStream(out)) {
            dataStream.outputStream = outputStream;
            dataStream.WriteShort(getProtoCode());
            dataStream.WriteByte(Sex);
            dataStream.WriteUTF8String(RoleNickName);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return out.toByteArray();    }
    public static RoleOperation_CreatePlayerProto GetProto(byte[] buffer) {
        RoleOperation_CreatePlayerProto proto = new RoleOperation_CreatePlayerProto();
        try (DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(buffer))) {
            dataStream.inputStream = inputStream;
            proto.Sex = (byte)dataStream.ReadByte();
            proto.RoleNickName = dataStream.ReadUTF8String();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return proto;
    }
}